package com.rrd.dw.mr.gzip.kafka;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.ylbusiness.YinLianBusinessBlackListRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 银联-黑名单
 *
 * @author guoqiang
 */

public class YinLianBusinessBlackListRecordParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 银联-黑名单
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        YinLianBusinessBlackListRecord obj = (YinLianBusinessBlackListRecord) model;
        String data = obj.getData();
        JSONObject dataJson = JSON.parseObject(data);

        StringBuilder sb = getBaseInfo(obj, successful);
        //关键字类型
        sb.append(dataJson.getString("keyType")).append(CRT001);
        //身份证号
        sb.append(dataJson.getString("certId")).append(CRT001);
        //银行卡号
        sb.append(dataJson.getString("cardNo")).append(CRT001);
        //商户标识类型
        sb.append(dataJson.getString("mchntCodeTp")).append(CRT001);
        //商户标识
        sb.append(dataJson.getString("mchntCode")).append(CRT001);
        //手机号
        sb.append(dataJson.getString("telephone")).append(CRT001);
        //应答码
        sb.append(dataJson.getString("respCode")).append(CRT001);
        //应答码描述
        sb.append(dataJson.getString("respMsg")).append(CRT001);
        //细分应答码
        sb.append(dataJson.getString("detailRespCode")).append(CRT001);
        //细分应答码描述
        sb.append(dataJson.getString("detailRespMsg")).append(CRT001);
        key.set(getKey());
        val.set((sb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_yinlian_business_blacklist_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.YINLIAN_BUSINESS_BLACKLIST.toString();
    }

    @Override
    public String getComment() {
        return "银联-黑名单";
    }
}
